home *** CD-ROM | disk | FTP | other *** search
- package netscape.applet;
-
- import java.io.PrintStream;
-
- class AppletThreadKiller implements Runnable {
- AppletThreadList list = new AppletThreadList();
- Thread[] threadsSnapshot;
- int threadsSnapshotLen;
- boolean keepRunning = true;
- static ThreadGroup clientThreadGroup;
- static final int SHUTDOWN_TIMEOUT = 30000;
-
- AppletThreadKiller() {
- SecurityManager.enablePrivilege("UniversalThreadGroupAccess");
- clientThreadGroup = new ThreadGroup("ClientThreadGroup");
- Thread var1 = new Thread(this, "Applet Thread Killer");
- var1.start();
- }
-
- synchronized void addAppletThread(AppletThreadList var1) {
- this.list.appendElement(var1);
- this.notify();
- }
-
- synchronized AppletThreadList getAppletThread() {
- AppletThreadList var1 = null;
-
- while(this.keepRunning && this.list.isEmptyList()) {
- try {
- this.notify();
- this.wait();
- } catch (InterruptedException var2) {
- }
- }
-
- if (!this.list.isEmptyList()) {
- var1 = (AppletThreadList)this.list.next;
- ((DoubleLinkedList)var1).remove();
- } else {
- this.notify();
- }
-
- return var1;
- }
-
- synchronized boolean waitForAll() {
- this.notify();
-
- try {
- this.wait((long)(30000 * (MozillaAppletContext.totalApplets + 1)));
- } catch (InterruptedException var1) {
- }
-
- return this.list.isEmptyList();
- }
-
- synchronized boolean shutdown() {
- if (MozillaAppletContext.debug >= 7) {
- System.out.println("##### shutting down all applets");
- }
-
- this.keepRunning = false;
- this.notify();
-
- try {
- this.wait((long)(30000 * (MozillaAppletContext.totalApplets + 1)));
- } catch (InterruptedException var2) {
- if (MozillaAppletContext.debug >= 7) {
- System.out.println("##### applets shutdown interrupted: " + var2);
- }
- }
-
- boolean var1 = clientThreadGroup.activeCount() == 0;
- if (MozillaAppletContext.debug >= 7) {
- System.out.println("##### applets shutdown complete: " + (var1 ? "successful" : "failed"));
- }
-
- return var1;
- }
-
- public void run() {
- Object var1 = null;
- Object var2 = null;
- Object var3 = null;
- Object var4 = null;
- Object var5 = null;
-
- while(this.keepRunning || !this.list.isEmptyList()) {
- try {
- var1 = null;
- var2 = null;
- MozillaAppletContext var93 = null;
- var4 = null;
- var5 = null;
- AppletThreadList var6 = this.getAppletThread();
- if (var6 != null) {
- ThreadGroup var90 = var6.group;
- var6.group = null;
- DerivedAppletFrame var92 = var6.frame;
- var6.frame = null;
- if (var92 != null) {
- var93 = var92.context;
- }
-
- Task var95 = var6.task;
- var6.task = null;
- Object var98 = null;
- String var97 = var92 != null ? var92.getAppletName() : var95.taskName();
- synchronized(var90){}
-
- try {
- if (var92 != null) {
- var92.requestShutdown();
- } else {
- var95.requestShutdown();
- }
-
- if (!this.keepRunning) {
- int var9 = var90.activeCount();
- if (this.threadsSnapshot == null || this.threadsSnapshotLen < var9) {
- this.threadsSnapshot = new Thread[var9];
- this.threadsSnapshotLen = var9;
- }
-
- var90.enumerate(this.threadsSnapshot);
-
- for(int var10 = 0; var10 < var9; ++var10) {
- Thread var11 = this.threadsSnapshot[var10];
- if (var11.isDaemon()) {
- var11.stop();
- }
- }
-
- this.threadsSnapshot = null;
- }
-
- if (var90.activeCount() > 0) {
- try {
- var90.wait(30000L);
- } catch (InterruptedException var81) {
- System.err.println("# Interrupted while waiting for applet to die: " + var97);
- }
- }
-
- if (var90.activeCount() > 0) {
- System.out.println("# Applet " + var97 + " did not shut down within " + 30 + " seconds -- killing it.");
-
- try {
- SecurityManager.enablePrivilege("UniversalThreadGroupAccess");
- var90.stop();
- var90.wait(5000L);
- } catch (InterruptedException var79) {
- System.err.println("# Interrupted while stopping thread group: " + var97);
- } finally {
- SecurityManager.revertPrivilege();
- }
- }
-
- try {
- SecurityManager.enablePrivilege("UniversalThreadGroupAccess");
- if (var90 instanceof AppletThreadGroup) {
- ((AppletThreadGroup)var90).destroyItDamnIt();
- } else if (var90 instanceof TaskThreadGroup) {
- ((TaskThreadGroup)var90).destroyItDamnIt();
- } else {
- var90.destroy();
- }
- } catch (Exception var85) {
- if (MozillaAppletContext.debug >= 7) {
- System.err.println("# Exception while destroying group: " + var97);
- ((Throwable)var85).printStackTrace();
- }
- } finally {
- SecurityManager.revertPrivilege();
- }
-
- if (var92 != null) {
- var92.destroy();
- }
- } catch (Throwable var87) {
- throw var87;
- }
-
- if (var93 != null) {
- synchronized(var93){}
-
- try {
- if (var93.appletFrames != null && var93.appletFrames.isEmpty()) {
- if (MozillaAppletContext.debug >= 7) {
- System.err.println("# destroyApplet: destroying context for contextID " + var93.contextID);
- }
-
- var93.destroy();
- }
- } catch (Throwable var84) {
- throw var84;
- }
- }
- }
- } catch (Exception var88) {
- System.out.println("Exception occurred while destroying applet: " + ((Throwable)var88).toString());
- if (MozillaAppletContext.debug >= 7) {
- ((Throwable)var88).printStackTrace();
- }
- }
- }
-
- try {
- SecurityManager.enablePrivilege("UniversalThreadGroupAccess");
- clientThreadGroup.stop();
- clientThreadGroup.destroy();
- } catch (Exception var82) {
- if (MozillaAppletContext.debug >= 7) {
- System.err.println("# Exception while destroying group: " + clientThreadGroup);
- ((Throwable)var82).printStackTrace();
- }
- } finally {
- SecurityManager.revertPrivilege();
- }
-
- if (MozillaAppletContext.debug >= 7) {
- System.out.println("# all applets and programs killed");
- }
-
- synchronized(this){}
-
- try {
- this.notify();
- } catch (Throwable var78) {
- throw var78;
- }
-
- }
-
- public String toString() {
- return new String("Applet thread killer! Applets to be disposed: " + this.list);
- }
-
- synchronized void dumpState(PrintStream var1) {
- AppletThreadList var2 = this.list;
- if (var2 != null) {
- boolean var3 = false;
-
- do {
- DerivedAppletFrame var4 = var2.frame;
- Task var5 = var2.task;
- if (!var3 && (var4 != null || var5 != null)) {
- var1.println("# Zombies:");
- var3 = true;
- }
-
- if (var4 != null) {
- try {
- var4.dumpState(var1, 1);
- } catch (Exception var6) {
- var1.println("\tApplet: " + var4);
- }
- } else if (var5 != null) {
- var1.println("\tTask: " + var5);
- }
-
- var2 = (AppletThreadList)var2.next;
- } while(var2 != this.list);
-
- }
- }
- }
-